package com.example.demo.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.example.demo.common.Result;
import com.example.demo.entity.Notice;
import com.example.demo.entity.Params;

import com.example.demo.exception.CustomException;
import com.example.demo.service.NoticeService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@CrossOrigin
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Resource
    private NoticeService noticeService;
    @PostMapping
    public Result save(@RequestBody Notice notice) {
        if (notice.getId() == null) {
            noticeService.add(notice);
            return Result.success();
        } else {
            noticeService.update(notice);
            return Result.success();
        }
    }
    @GetMapping
    public Result findAll()
    {
        return Result.success(noticeService.findAll());

    }
    @GetMapping("/search")
    public Result findBySearch(Params params) {
        PageInfo<Notice> homeworklist = noticeService.findBySearch(params);
        return Result.success(homeworklist);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        noticeService.delete(id);
        return Result.success();
    }
    @PutMapping("/delBatch")
    public Result deleteBatch(@RequestBody List<Notice> list)
    {
        for (Notice notice : list) {
            noticeService.delete(notice.getId());
        }
       return Result.success();
    }

}
